import 'package:base_plugin/base_plugin.dart';
import 'package:finance_app/src/common/app_colors.dart';
import 'package:finance_app/src/common/config.dart';
import 'package:finance_app/src/widgets/common/chat_image_watch.dart';
import 'package:finance_app/src/widgets/style/image_style.dart';
import 'package:flutter/material.dart';

import 'text_chat_item.dart';

class ImageChatItem extends StatelessWidget {
  final bool isTop;
  final String content;
  final dynamic actions;
  final ValueChanged<dynamic> onAction;
  final int id;

  const ImageChatItem(
      {Key key,
      this.id,
      this.isTop = false,
      this.content,
      this.actions,
      this.onAction})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    final style = TextChatItemStyle.of(context);
    List<Widget> actionWidgets = [];
    if (actions != null && actions is List) {
      for (var i = 0; i < actions.length; i++) {
        final action = actions[i];
        actionWidgets.add(PressedOpacityButton(
          onPressed: () {
            onAction?.call(action);
          },
          padding: EdgeInsets.symmetric(
            vertical: getDp(10),
          ),
          child: Text(
            action['text'],
            style: TextStyle(
              color: aceBlueColor,
              fontSize: getSp(14),
              fontWeight: FontWeight.w400,
              height: 22 / 14,
            ),
          ),
        ));
      }
    }
    return Container(
      clipBehavior: Clip.antiAlias,
      margin: EdgeInsets.only(
          top: isTop == false ? getDp(10) : 0.0, left: getDp(13)),
      constraints: BoxConstraints(
        maxWidth: getDp(249),
      ),
      decoration: BoxDecoration(
          borderRadius: BorderRadius.only(
        bottomRight:
            style?.archerAlign == Alignment.bottomRight && isTop == true
                ? Radius.circular(0.0)
                : Radius.circular(16),
        bottomLeft: Radius.circular(16),
        topRight: Radius.circular(16),
        topLeft: style?.archerAlign == Alignment.topLeft && isTop == true
            ? Radius.circular(0.0)
            : Radius.circular(16),
      )),
      child: Column(
        children: [
          Material(
            clipBehavior: Clip.antiAlias,
            borderRadius: BorderRadius.circular(getDp(5)),
            child: ChatImageWatch(
              tag: id,
              url: content,
            ),
          ),
          ...actionWidgets,
        ],
      ),
    );
  }
}
